package com.example.com.skills_utf8;

import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.widget.ImageView;
import android.widget.Toast;

import com.app.BaseActivity;
import com.soundcloud.android.crop.Crop;

import java.io.File;

public class _70Activity extends BaseActivity {


    ImageView iv_content;

    @Override
    public Object InitLayout() {
        return R.layout.activity__70;
    }

    @Override
    public void InitView() {
        iv_content = (ImageView)findViewById(R.id.iv_content);
    }

    @Override
    public void InitListener() {

    }

    @Override
    public void InitProcess() {

        Crop.pickImage(this);
    }



    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent result) {
        if (requestCode == Crop.REQUEST_PICK && resultCode == RESULT_OK) {
            Log.e(TAG, "beginCrop");
            beginCrop(result.getData());
        } else if (requestCode == Crop.REQUEST_CROP) {
            Log.e(TAG, "handleCrop");
            handleCrop(resultCode, result);
        }
    }

    private void beginCrop(Uri source) {
        Uri destination = Uri.fromFile(new File(getCacheDir(), "cropped"));
        Crop.of(source, destination).asSquare().start(this);
    }

    private void handleCrop(int resultCode, Intent result) {
        if (resultCode == RESULT_OK) {
            iv_content.setImageURI(Crop.getOutput(result));
        } else if (resultCode == Crop.RESULT_ERROR) {
            Toast.makeText(this, Crop.getError(result).getMessage(), Toast.LENGTH_SHORT).show();
        }
    }


}
